import { getToken } from '../api/blogs.js'

const actions = {
    getTokenDefault: (ctx) => {
        const auth = {
            "client_id": "f09978bc-b9e0-457b-a03d-3c71c2f25b27",
            "client_secret": "8aQ2DOJ-n7CW53ROu4XantZzMlVNUiwHIAUaM4upk4pYziMDQDFIkxXgFMO1PP_6xkHH0MYuPVxtkjoW",
            "grant_type": "client_credentials"
        }
        getToken(auth)
        .then(res => {
            if(res.statusCode === 200){
                const token = {
                    token: res.data.token_type +' '+ res.data.access_token,
                    expires: new Date().getTime() + res.expires_in
                }
                ctx.commit('setToken',  token)
            }else{
                uni.showModal({
                    content: '获取token错误,请联系作者',
                    showCancel: false
                });
                ctx.commit('setToken',  null)
            }
            console.log(res)
        })
        .catch(e => {
            console.log(e)
        })
    }
}

export default actions